#!/usr/bin/python

import gdata.gauth
import gdata.docs.data
import gdata.docs.client
import gdata.service

import getpass
import printfeed 
import download
#we have setup an object that actually accesses the api
client = gdata.docs.client.DocsClient(source='backupv1')
client.ssl = True #force all api  requests through https | good
client.http_client.debug = False # Set to True for dbugging http requests | no idea what that means


user = raw_input('Provide user name ')
passw = getpass.getpass()
#passw = 'edeeyyddncuppqtc'



try:
	client.ClientLogin(user,passw,client.source)
except gdata.client.BadAuthentication:
	print "Wrong Authentication Information"
#	print 'Please visit ' + client.captcha_url
#	answer = raw_input('Write Captcha ')
#	client.ClientLogin(user, passw, source='backupv1',captcha_token = client.captcha_token, captcha_response=answer) 

feed = client.GetDocList()
entries=printfeed.PrintFeed(feed)

strings=download.Download(entries, 'document')

for i in strings:
	get=client.GetDoc(i)
	client.Download(get,'./'+get.title.text+'.doc')
	print "downloading "+get.title.text
